'''
    Module to manage modes and mode changes
'''

import re

add = re.compile(r'\+([^- ]+)')
sub = re.compile(r'-([^+ ]+)')

def arithmetic(original, new):
    '''
        Modify mode original with new, ignoring bans/invites/etc
    '''
    global add, sub
    
    added = add.search(new)
    if added:
        added = added.group(0)[1:]
    else:
        added = ''
        
    subtracted = sub.search(new)
    if subtracted:
        subtracted = subtracted.group(0)[1:]
    else:
        subtracted = ''
    
    for i in 'aoqhvbeI':
        added = added.replace(i, '')
        subtracted = subtracted.replace(i, '')
    
    original += added
    for i in subtracted:
        original.replace(i, '')
    
    return original